package targaman.moltenwow.autovoter.Logger;

import javafx.application.Platform;
import javafx.scene.control.TextArea;
import targaman.moltenwow.autovoter.gui.Main;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Jonathan on 27/12/2014.
 */
public class MoltenLogger {

    static org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(MoltenLogger.class.getName());



    public static void Log(String message)
    {
        if(Main.scene != null) {
            TextArea area = (TextArea) Main.scene.lookup("#console");
            if (area != null) {
                if(area.getText().length()>500)
                {
                    Platform.runLater(() -> area.setText(""));
                }
                DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
                Date date = new Date();
                String currentText = "" + area.getText();
                String nextText = dateFormat.format(date) +": " +  message + "\n" + currentText;
                Platform.runLater(() -> area.setText(nextText));

            }
        }
        log.debug(message);

    }

}
